<?php
declare (strict_types = 1);
if (!function_exists('totrue')) {
    /**
     * 返回操作成功json信息
     * @param array $object 当前返回对象
     * @param string $special 特殊返回对象处理 有类型：select
     */
    function totrue($message = '成功', $code = 0, $is_json = true)
    {
        return tocode($code, $message, [], 0, [], $is_json);
    }
}

if (!function_exists('tofalse')) {
    /**
     * 返回json错误信息
     * @param string $status 当前错误状态
     * @param string $message 返回错误信息前追加内容,默认为空
     */
    function tofalse($message = '失败', $code = 100, $is_json = true)
    {
        return tocode($code, $message, [], 0, [], $is_json);
    }
}
if (!function_exists('todata')) {
    /**
     * 返回json错误信息
     * @param string $status 当前错误状态
     * @param string $message 返回错误信息前追加内容,默认为空
     */
    function todata($data, $count = 0, $code = 0, $is_json = true)
    {
        return tocode($code, '', $data, $count, [], $is_json);
    }
}
if (!function_exists('tocode')) {
    /**
     * json返回错误结果
     */
    function tocode($code = 0, $msg = "", $data = [], $count = 0, $other = [], $is_json = true)
    {
        $result['code'] = $code;
        if (!empty($msg)) {
            $result['msg'] = $msg;
        }
        if (!empty($data)) {
            $result['data'] = $data;
        }
        if (!empty($count)) {
            $result['count'] = $count;
        }
        if (!empty($other)) {
            $result['other'] = $other;
        }
        if ($is_json) {
            header("Access-Control-Allow-Origin:*");
            header('Access-Control-Allow-Methods:POST,GET,PUT,DELETE,OPTIONS');
            header('Content-Type:application/json; charset=utf-8');
            echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
            exit;
        }
        return $result;
    }
}
/**
 * 多个连续空格只保留一个
 *
 * @param string $string 待转换的字符串
 * @return string $string 转换后的字符串
 */
if (!function_exists('merge_spaces')) {
    function merge_spaces($string)
    {
        return preg_replace("/\s(?=\s)/", "\\1", $string);
    }
}
/**============配置开始===========*/
if (!function_exists('config_group')) {
    function config_group($name = false, $default = '')
    {
        try {
            $list = cache('config_data'); //获取系统配置文件
            if (empty($list)) {
                $list = (new \x_mier\Config())->lists();
            }
            if ($name) {
                $list = !empty($list[$name]) ? $list[$name] : '';
                if (is_array($list) && $default !== '' && isset($list[$default])) {
                    return $list[$default];
                }
                if (empty($list) && $default !== '') {
                    return $default;
                }
            }
        } catch (\Exception $e) {
            return $default;
        }
        return $list;
    }
}
/**============配置结束===========*/
/**
 * 时间戳转换函数
 */
if (!function_exists('time_date')) {
    function time_date($time, $type = false)
    {
        if ($type) {
            $res = date('Y-m-d', $time);
        } else {
            $res = date('Y-m-d H:i:s', $time);
        }
        return $res;
    }
}
/**
 * 树状生成
 */
if (!function_exists('get_trees')) {
    function get_trees($data, $children = 'child', $pid = '0', $parentField = 'pid', $pkField = 'id', $is_array = true)
    {
        $tree = array();
        foreach ($data as $k => $v) {
            if ($is_array) {
                if ($v[$parentField] == $pid) {
                    $temp = get_trees($data, $children, $v[$pkField], $parentField, $pkField, $is_array);
                    if (!empty($temp)) {
                        //分层
                        $v[$children] = get_trees($data, $children, $v[$pkField], $parentField, $pkField, $is_array);
                    }
                    $tree[] = $v;
                }
            } else {
                if ($v->$parentField == $pid) {
                    $temp = get_trees($data, $children, $v->$pkField, $parentField, $pkField, $is_array); //$data是对象则改为$v－>$pkField
                    if (!empty($temp)) {
                        //分层
                        $v->$children = get_trees($data, $children, $v->$pkField, $parentField, $pkField, $is_array);
                    }
                    $tree[] = $v;
                }
            }
        }
        return $tree;
    }
}
/**
 * 钉钉机器人推送
 */
if (!function_exists('dingtalk_push')) {
    function dingtalk_push($title, $error = false)
    {
        // 机器人hook地址
        $webhook = "https://oapi.dingtalk.com/robot/send?access_token=" . config_group('webhook_token');
        if (is_array($title)) {
            $data = $title;
        } else {
            $data = [
                'msgtype' => 'markdown',
                "markdown" => [
                    "title" => $title,
                    "text" => $error,
                ],
            ];
        }
        post($webhook, $data);
    }
}
if (!function_exists('baidu_fanyi')) {
    function fanyi($value)
    {
        //空格转下划线
        $arr = str_replace(' ', '_', $value);
        if (!is_file('./static/json/fanyi.json')) {
            touch('./static/json/fanyi.json');
        }
        $file = file_get_contents('./static/json/fanyi.json');
        if ($file) {
            $file = json_decode($file, true);
            if (!empty($file[$arr])) {
                return $file[$arr];
            }
        }
        $fanyi = baidu_fanyi($value);
        $data = [
            $arr => $fanyi,
        ];
        if ($file) {
            $result = array_merge($data, $file);
        } else {
            $result = $data;
        }
        file_put_contents('./static/json/fanyi.json', json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
        return $fanyi;
    }
}
if (!function_exists('baidu_fanyi')) {
    function baidu_fanyi($value, $from = "en", $to = "zh")
    {
        $baidu = config_group('baidu_fanyi');
        $appid = $baidu['appid']; //您注册的API Key
        $key = $baidu['key']; //密钥
        $salt = rand(10000, 99999); //随机数
        $sign = md5($appid . $value . $salt . $key); //签名
        $value = urlencode($value);
        //生成翻译API的URL
        $url = "http://api.fanyi.baidu.com/api/trans/vip/translate?q=$value&appid=$appid&salt=$salt&from=$from&to=$to&sign=$sign";
        $text = json_decode(get($url));
        $lan = $text->trans_result;
        // $result = implode('|', $lan);
        $result = '';
        foreach ($lan as $k => $v) {
            if ($k == 0) {
                $result .= ucwords($v->dst);
            } else {
                $result .= ucwords($v->dst) . "\n";
            }
        }
        return $result;
    }
}
/**
 * 解析url中参数信息，返回参数数组
 */
if (!function_exists('convert_url_query')) {
    function convert_url_query($query)
    {
        $queryParts = explode('&', $query);

        $params = array();
        foreach ($queryParts as $param) {
            $item = explode('=', $param);
            $params[$item[0]] = $item[1];
        }

        return $params;
    }
}
/**
 * 把数组拼接成url参数形式
 */
if (!function_exists('get_url_query')) {
    function get_url_query($array_query)
    {
        $tmp = array();
        foreach ($array_query as $k => $param) {
            $tmp[] = $k . '=' . $param;
        }
        $params = implode('&', $tmp);
        return $params;
    }
}
/**
 * 根据地址 获取经纬度
 * @param $address
 * @return mixed
 */
if (!function_exists('get_latlag')) {
    function get_latlag($address, $key = false)
    {
        if (empty($key)) {
            $key = config_group('gaode_key');
        }
        $url = 'http://restapi.amap.com/v3/geocode/geo?address=' . $address . '&key=' . $key;
        if ($result = file_get_contents($url)) {
            $result = json_decode($result, true);
            //判断是否成功
            if (!empty($result['count'])) {
                return $result;
            } else {
                return false;
            }
        }
    }
}
/**
 * 根据经纬度 获取地址
 * @param $address
 * @return mixed
 */
if (!function_exists('get_address')) {
    function get_address($location, $key = false)
    {
        if (empty($key)) {
            $key = config_group('gaode_key');
        }
        $url = "http://restapi.amap.com/v3/geocode/regeo?output=json&location=" . $location . "&key=" . $key;
        if ($result = file_get_contents($url)) {
            $result = json_decode($result, true);
            if (!empty($result['status']) && $result['status'] == 1) {
                return $result;
            } else {
                return false;
            }
        }
    }
}
/* 记录日志
 * @param  [type] $uid         [用户id]
 * @param  [type] $username    [用户名]
 * @param  [type] $description [描述]
 * @param  [type] $status      [状态] 6 操作成功  5 操作失败
 * @param  [type] $type        [删除日志启用]
 */
if (!function_exists('writelog')) {
    function writelog($description, $status, $type = 0, $uid = '', $username = '', $types = '')
    {
        (new \x_mier\Config())->writelog($description, $status, $type, $uid, $username, $types);
    }
}
/*
 * 淘宝接口：根据ip获取所在城市名称
 */
if (!function_exists('get_ip_area')) {
    function get_ip_area($ip)
    {
        if ($ip == '127.0.0.1') {
            return '内网IP';
        }
        try {
            $url = "https://ip.taobao.com/outGetIpInfo?ip={$ip}&accessKey=alibaba-inc";
            $ret = get($url);
            $arr = json_decode($ret, true);
            if ($arr['code'] == 1) {
                return '';
            } else {
                return $arr['data']['country'] . $arr['data']['region'] . $arr['data']['city'] . $arr['data']['isp'];
            }
        } catch (\Exception $e) {
            return $e->getMessage();
        }
        return '';
    }
}
/**
 * 发送一个POST请求
 * @param string $url     请求URL
 * @param array  $data  请求参数
 * @param array  $header 扩展参数
 * @return mixed|string
 */
if (!function_exists('post')) {
    function post($url, $data = [], $header = [], $header_null = false, $data_re = false)
    {
        $req = (new \x_mier\Config())->send_request($url, $data, 'POST', $header, $header_null, $data_re);
        return $req['ret'] ? $req['msg'] : '';
    }
}

/**
 * 发送一个GET请求
 * @param string $url     请求URL
 * @param array  $data  请求参数
 * @param array  $header 扩展参数
 * @return mixed|string
 */
if (!function_exists('get')) {
    function get($url, $data = [], $header = [], $header_null = false, $data_re = false)
    {
        $req = (new \x_mier\Config())->send_request($url, $data, 'GET', $header, $header_null, $data_re);
        return $req['ret'] ? $req['msg'] : '';
    }
}
/**
 * json中的Key增加上引号.
 */
if (!function_exists('json_replace_key')) {
    function json_replace_key($str)
    {
        $str = trim($str);
        $str = ltrim($str, '(');
        $str = rtrim($str, ')');
        $a = preg_split('#(?<!\\\\)\"#', $str);
        for ($i = 0; $i < count($a); $i += 2) {
            $s = $a[$i];
            $regex = '/([^\{\}\:\,]*)(\:)([^\{\}\:\,]*)/';
            $s = preg_replace($regex, "\"$1\"$2\"$3\"", $s);
            $a[$i] = $s;
        }
        return '[' . implode('"', $a) . ']';
    }
}

/**
 * 用户密码加密
 * @param $str
 * @param string $key
 * @return string
 */
if (!function_exists('passwd')) {
    function passwd($str, $key = false)
    {
        if (empty($key)) {
            $key = config('helper.passwd_key');
        }
        return '' === $str ? '' : md5(sha1((string) $str) . $key);
    }
}
//生成唯一订单号
if (!function_exists('order_number')) {
    function order_number()
    {
        date_default_timezone_set('PRC');
        $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
        $orderSn = '';
        $orderSn .= $yCode[(intval(date('Y')) - 1970) % 10];
        $orderSn .= strtoupper(dechex((int) date('m')));
        $orderSn .= date('d') . substr((string) time(), -5);
        $orderSn .= substr(microtime(), 2, 5);
        $orderSn .= sprintf('%02d', mt_rand(0, 99));
        return $orderSn;
    }
}
/**
 *  作用：产生随机字符串，不长于32位
 */
if (!function_exists('create_noncestr')) {
    function create_noncestr($length = 32)
    {
        $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
        $str = "";
        for ($i = 0; $i < $length; $i++) {
            $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
        }
        return $str;
    }
}
/* 毫秒时间戳转换成日期 */
if (!function_exists('msecdate')) {
    function msecdate($time)
    {
        $tag = 'Y-m-d';
        $tag1 = 'H:i:s';
        $a = substr($time, 0, 10);
        $b = substr($time, 10);
        $date = date($tag, (int) $a);
        $date1 = date($tag1, (int) $a);
        return $date . 'T' . $date1 . '.' . $b . '+08:00';
    }
}
//返回当前的毫秒时间戳
if (!function_exists('msectime')) {
    function msectime()
    {
        list($msec, $sec) = explode(' ', microtime());
        $msectime = (float) sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
        return $msectime;
    }
}

/**
 * 生成文件夹及文件
 * @param [type] $path    路径
 * @param [type] $name    文件名
 * @param [type] $content 内容
 */
if (!function_exists('add_dir_file')) {
    function add_dir_file($path, $name = false, $content = false)
    {
        $result = false;
        if (!is_dir($path)) {
            $path = iconv("UTF-8", "GBK", $path);
            mkdir($path, 0777, true);
        }
        if ($name) {
            file_put_contents($path . $name, $content);
        }
        $result = true;
        return $result;
    }
}
/**
 * 根据二维数组某个字段的值查找数组
 * @param [type] $array    数组
 * @param [type] $index    字段名
 * @param [type] $value    值
 * @param [type] $type     类型(是否将字符串转小写)
 */
if (!function_exists('filter_by_value')) {
    function filter_by_value($array, $index, $value, $type = false, $chlid = 'child')
    {
        $newarray = [];
        if (is_array($array) && count($array) > 0) {
            foreach ($array as $k => $v) {
                if (!empty($v[$index])) {
                    if (($type == true ? strtolower($v[$index]) : $v[$index]) == ($type == true ? strtolower($value) : $value)) {
                        return $v;
                    }
                }
                if ($chlid) {
                    if (!empty($v[$chlid])) {
                        $newarray = filter_by_value($v[$chlid], $index, $value, $type);
                        if ($newarray) {
                            return $newarray;
                        }
                    }
                }
            }
        }
        return $newarray;
    }
}
/**
 * 二维数组根据某个字段进行分组
 * @param $arr
 * @param $key
 * @param string $col_id
 * @return array
 * created by Steven at 2020-7-31 11:56
 */
if (!function_exists('array_group_by')) {
    function array_group_by($arr, $key, $col_id = 'id')
    {
        $grouped = array();
        foreach ($arr as $value) {
            $grouped[$value[$key]][$value[$col_id]] = $value;
        }
        if (func_num_args() > 2) {
            $args = func_get_args();
            foreach ($grouped as $key => $value) {
                $parms = array_merge($value, array_slice($args, 2, func_num_args()));
                $grouped[$key] = call_user_func_array('array_group_by', $parms);
            }
        }
        return $grouped;
    }
}
/**
 * 获取文件夹或目录的大小
 */
if (!function_exists('get_folder_size')) {
    function get_folder_size($dir)
    {
        $count_size = 0;
        $count = 0;
        if (!is_dir($dir)) {
            return filesize($dir);
        }
        $dir_array = scandir($dir);
        foreach ($dir_array as $key => $filename) {
            if ($filename != "" && $filename != "." && $filename != "..") {
                if (is_dir($dir . "/" . $filename)) {
                    $new_foldersize = get_folder_size($dir . "/" . $filename);
                    $count_size = $count_size + $new_foldersize;
                } else if (is_file($dir . "/" . $filename)) {
                    $count_size = $count_size + filesize($dir . "/" . $filename);
                    $count++;
                }
            }
        }
        return $count_size;
    }
}
/**
 * 格式化字节大小
 * @param  number $size      字节数
 * @param  string $delimiter 数字和单位分隔符
 * @return string            格式化后的带单位的大小
 */
if (!function_exists('format_bytes')) {
    function format_bytes($size, $delimiter = '')
    {
        $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
        for ($i = 0; $size >= 1024 && $i < 5; $i++) {
            $size /= 1024;
        }
        return round(((int) ($size . $delimiter)), 2) . $units[$i];
    }
}
/**
 * 二维数组按某个字段排序
 * @param $arr 二维数组
 * @param $field 排序字段
 * @param string $direction 排序顺序标志 SORT_DESC 降序；SORT_ASC 升序
 * @return mixed
 */
if (!function_exists('arrayToSort')) {
    function array_to_sort($arr, $field, $direction = "SORT_DESC")
    {
        $arrSort = [];
        foreach ($arr as $uniqid => $row) {
            foreach ($row as $key => $value) {
                $arrSort[$key][$uniqid] = $value;
            }
        }
        if (!empty($arr)) {
            array_multisort($arrSort[$field], constant($direction), $arr);
        }
        return $arr;
    }
}

/**
 * 将字符解析成数组
 * @param $str
 */
if (!function_exists('parse_params')) {
    function parse_params($str)
    {
        $arrParams = [];
        parse_str(html_entity_decode(urldecode($str)), $arrParams);
        return $arrParams;
    }
}
/**
 * get_rand_code 获取随机6位数字验证码
 * @param int $len
 * @return string
 */
if (!function_exists('get_rand_code')) {
    function get_rand_code($len = 6)
    {
        $chars = array(
            "1", "2",
            "3", "4", "5", "6", "7", "8", "9",
        );
        $charsLen = count($chars) - 1;
        shuffle($chars);
        $output = "";
        for ($i = 0; $i < $len; $i++) {
            $output .= $chars[mt_rand(0, $charsLen)];
        }
        return $output;
    }
}

/**
 * 删除文件夹及文件夹内文件函数，支持中文路径
 * @param string $path 文件夹路径
 * @param string $delDir 是否删除该文件夹
 * @return boolean
 */
if (!function_exists('delete_dir_file')) {
    function delete_dir_file($path, $del = true, $no_del = false)
    {
        try {
            if (!is_array($no_del)) {
                $no_del = [$no_del];
            }
            if (is_dir($path)) {
                $path = iconv("UTF-8", "GBK", $path);
                $handle = opendir($path);
                if ($handle) {
                    while (false !== ($item = readdir($handle))) {
                        if (($item != ".") && ($item != "..") && (!in_array($item, $no_del))) {
                            is_dir("$path/$item") ? delete_dir_file("$path/$item", $del, $no_del) : unlink("$path/$item");
                        }
                    }
                    closedir($handle);
                    if ($del) {
                        rmdir($path);
                    }
                }
                $result = true;
            }
        } catch (\Throwable $e) {
            $result = false;
        }
        return $result;
    }
}
/**
 * 复制文件夹
 * @param $source
 * @param $dest
 */
if (!function_exists('copy_dir')) {
    function copy_dir($source, $dest)
    {
        if (!file_exists($dest)) {
            mkdir($dest);
        }

        $handle = opendir($source);
        while (($item = readdir($handle)) !== false) {
            if ($item == '.' || $item == '..') {
                continue;
            }
            $_source = $source . '/' . $item;
            $_dest = $dest . '/' . $item;
            if (is_file($_source)) {
                copy($_source, $_dest);
            }
            if (is_dir($_source)) {
                copy_dir($_source, $_dest);
            }
        }
        closedir($handle);
    }
}
/**
 * lat 纬度
 * lon 经度
 * raidus 公里
 */
if (!function_exists('get_range')) {
    function get_range($lat, $lon, $raidus)
    {
        define('PI', 3.1415926535898);
        define('EARTH_RADIUS', 6378.137);
        //计算纬度
        $degree = (24901 * 1609) / 360.0;
        $dpmLat = 1 / $degree;
        $radiusLat = $dpmLat * $raidus;
        $minLat = $lat - $radiusLat; //得到最小纬度
        $maxLat = $lat + $radiusLat; //得到最大纬度

        //计算经度
        $mpdLng = $degree * cos($lat * (PI / 180));
        $dpmLng = 1 / $mpdLng;
        $radiusLng = $dpmLng * $raidus;
        $minLng = $lon - $radiusLng; //得到最小经度
        $maxLng = $lon + $radiusLng; //得到最大经度

        //范围
        $range = array(
            'minLat' => $minLat,
            'maxLat' => $maxLat,
            'minLon' => $minLng,
            'maxLon' => $maxLng,
        );
        return $range;
    }
}
/**
 * 返回附件地址
 */
if (!function_exists('_file')) {
    function _file($file_id = '', $is_null = false)
    {
        $default = request()->domain() . '/static/comn/img/default.png'; //系统默认图片
        if (empty($file_id)) {
            return empty($is_null) ? (is_array($file_id) ? array($default) : $default) : (is_array($file_id) ? array() : '');
        }
        $attachment = cache('attachment');
        if (empty($attachment)) {
            $attachment = (new \x_mier\Config())->attachment();
        }
        if (!is_array($file_id)) {
            $file = empty($attachment[$file_id]) ? 0 : $attachment[$file_id];
            if ($file) {
                $url = $file['storage'] == 0 ? request()->domain() . '/uploads/' : config_group('config_annex_url');
            }
            return empty($file) ? (empty($is_null) ? $default : '') : $url . str_replace("\\", "/", $file['url']);
        }
        $data = [];
        foreach ($file_id as $v) {
            $file = empty($attachment[$v]) ? 0 : $attachment[$v];
            if ($file) {
                $url = $file['storage'] == 0 ? request()->domain() . '/uploads/' : config_group('config_annex_url');
            }
            $data[] = empty($file) ? (empty($is_null) ? $default : '') : $url . str_replace("\\", "/", $file['url']);
        }
        return $data;
    }
}
//生成验签
if (!function_exists('sign_token')) {
    function sign_token($data, $exp_time = 604800, $key = 'x_mier')
    {
        $token = array(
            "iss" => $key, //签发者 可以为空
            "aud" => '', //面象的用户，可以为空
            "iat" => time(), //签发时间
            "nbf" => time() + 3, //在什么时候jwt开始生效  （这里表示生成100秒后才生效）
            "exp" => time() + $exp_time, //token 过期时间
            "data" => $data, //记录的userid的信息，这里是自已添加上去的，如果有其它信息，可以再添加数组的键值对
        );
        $jwt = x_mier\JWT\JWT::encode($token, $key, "HS256"); //根据参数生成了 token
        return $jwt;
    }
}

//验证token
if (!function_exists('check_token')) {
    function check_token($token, $key = 'x_mier')
    {
        try {
            x_mier\JWT\JWT::$leeway = 60; //当前时间减去60，把时间留点余地
            $decoded = x_mier\JWT\JWT::decode($token, $key, array('HS256')); //HS256方式，这里要和签发的时候对应
            $arr = (array) $decoded;
            $res['code'] = 0;
            $res['data'] = $arr['data'];
            return $res;
        } catch (\x_mier\JWT\SignatureInvalidException $e) { //签名不正确
            $res['code'] = 101;
            $res['msg'] = "签名不正确";
            return $res;
        } catch (\x_mier\JWT\BeforeValidException $e) { // 签名在某个时间点之后才能用
            $res['code'] = 102;
            $res['msg'] = "token失效";
            return $res;
        } catch (\x_mier\JWT\ExpiredException $e) { // token过期
            $res['code'] = 103;
            $res['msg'] = "token过期";
            return $res;
        } catch (\Exception $e) { //其他错误
            $res['code'] = 104;
            $res['msg'] = "token错误";
            return $res;
        }
    }
}
if (!function_exists('chinese_time')) {
    function chinese_time($val, $gs = 'Y年m月d日 H:i')
    {
        $date = date_parse_from_format($gs, $val);
        date_default_timezone_set("PRC");
        $res = mktime($date["hour"], $date["minute"], 0, $date["month"], $date["day"], $date["year"]);
        return $res;
    }
}
//复选框
if (!function_exists('check_box')) {
    function check_box($data, $arr)
    {
        foreach ($arr as $kk => $vv) {
            if (!empty($data[$vv])) {
                foreach ($data[$vv] as $kkk => $vvv) {
                    $data[$vv . "[{$kkk}]"] = $vvv;
                }
                unset($data[$vv]);
            }
        }
        return $data;
    }
}
//模型查询字段组装
if (!function_exists('where')) {
    function where(&$map, $data, $val = [])
    {
        if (empty($val)) {
            if (isset($data['page'])) {
                unset($data['page']);
            }
            if (isset($data['limit'])) {
                unset($data['limit']);
            }
            $val = array_keys($data);
        }
        if (!is_array($val)) {
            $val = explode(',', preg_replace("/\s|　/", "", $val));
        }
        foreach ($val as $k => $v) {
            if (isset($data[$v]) && (!empty($data[$v]) || $data[$v] === 0 || $data[$v] === '0')) {
                if (substr($v, -4) == 'time') {
                    $arr = explode(' - ', str_replace('%', '', $data[$v]));
                    if (count($arr) == 1) {
                        $start_time = strtotime(((strpos($data[$v], ':') !== false) ? (explode(' ', $data[$v])[0]) : ($data[$v] . ' 00:00:00')));
                        $end_time = $start_time + 86400 - 1;
                        $arr[0] = date('Y-m-d', $start_time);
                        $arr[1] = date('Y-m-d', $end_time);
                    }
                    $map[] = [$v, 'between time', $arr];
                } else if ((substr($data[$v], -1) == '%') || (substr($data[$v], 0, 1) == '%')) {
                    $map[] = [$v, 'like', $data[$v]];
                } else {
                    $map[] = [$v, '=', $data[$v]];
                }
            }
        }
    }

}
